package com.guli.gulimall.gulimallware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.guli.to.SkuHasStockVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.guli.gulimall.gulimallware.entity.WareSkuEntity;
import com.guli.gulimall.gulimallware.service.WareSkuService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;



/**
 * 商品库存
 *
 * @author zouzhi
 * @email 1245268075@qq.com
 * @date 2022-04-03 15:08:10
 */
@RestController
@RequestMapping("gulimallware/waresku")
@Api("库存系统")
public class WareSkuController {
    @Autowired
    private WareSkuService wareSkuService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("查询库存列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = wareSkuService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation("根据id查询库存")
    public R info(@PathVariable("id") Long id){
		WareSkuEntity wareSku = wareSkuService.getById(id);

        return R.ok().put("wareSku", wareSku);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("商品入库")
    public R save(@RequestBody WareSkuEntity wareSku){
		wareSkuService.save(wareSku);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改商品入库信息")
    public R update(@RequestBody WareSkuEntity wareSku){
		wareSkuService.updateById(wareSku);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation("批量根据id删除库存")
    public R delete(@RequestBody Long[] ids){
		wareSkuService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 查询商品是否有库存
     */
    @PostMapping("/hashStock")
    @ApiOperation("根据skuid查询是否有库存")
    public  List<SkuHasStockVo>  hashStock(@RequestBody  List<Long> sku_ids){
        List<SkuHasStockVo> hashStockDetails = wareSkuService.hashStock(sku_ids);
        return hashStockDetails;
    }

}
